<?php
function generateOptions($PositionEdit) {
    if (empty($PositionEdit)) {
        return false;
    }
    $ArPositions = Dracosys::getSessionValue(SESSION_INTERFACE, 'PositionList');
    $option = '<option value="">Selecione uma Fun&ccedil;ao</option>';
    foreach ($ArPositions as $Position) {
        if (!$Position->equals($PositionEdit)) {
            $option .= '<option value="' . $Position->getIDFuncao() . '">' . $Position->getStNome() . '</option>';
        }
    }
    return $option;
}

$Position = Dracosys::getSessionValue(SESSION_INTERFACE, 'PositionEdit');
$options = generateOptions($Position);
?>
<h2>Deletar Fun&ccedil;&atilde;o</h2>
<section id="DeletePosition">
    <form method="post" action="Setor/delete" name="FormDeleteFuncao">
        <?php if ($Position->hasProfiles()): ?>
            <section id="DeletePosition_ChangeProfiles">
                <div class="unique">Existem Perfis que possuem a Fun&ccedil;&atilde;o "<strong><?= $Position->getStNome() ?></strong>". Para conseguir deletar, você deve informar novas fun&ccedil;ões para os Perfis abaixo.</div>
                <table class="deleteTable">
                    <thead>
                        <tr>
                            <th>Perfil</th>
                            <th>Nova Fun&ccedil;&atilde;o</th>
                        </tr>
                    </thead>
                    <tbody>
        <?php foreach ($Position->getTPerfil() as $Profile): ?>
                            <tr>
                                <td><?= $Profile->getStPerfil() ?></td>
                                <td>
                                    <select name="IDFuncao_Perfil<?= $Profile->getIDPerfil() ?>">
                                        <?= $options ?>
                                    </select>
                                </td>
                            </tr>
        <?php endforeach; ?>
                    </tbody>
                </table>
            </section>
        <?php else: ?>
            <div class="unique">A Fun&ccedil;&atilde;o "<strong><?= $Position->getStNome() ?></strong>" está pronta para ser deletada.</div>
        <?php endif; ?>

        <div class="btn"><button class="v2">Deletar</button></div>
        <input type="hidden" name="IDFuncao" value="<?= treatUrl('id') ?>" />
    </form>
</section>